//
//  SDP_ViewControllerForCollectionTopRanking.m
//  ProjectB_
//
//  Created by sp on 16/3/22.
//  Copyright © 2016年 项目B. All rights reserved.
//

#import "SDP_ViewControllerForCollectionTopRanking.h"
#import "CWG_ViewControllerForDengLu.h"
#import "LWH_ViewControllerForCollect.h"
//#import "SDP_PlayerViewControllerForRanking.h"
#import "SDP_PlayerViewController.h"

#import "EveryDayModel.h"   //M
#import "SDP_ModelForTopRanking2.h"
#import "LWH_EveryDayModelForSection.h"

#import "EveryDayTableViewCell.h"   //V
#import "SDP_CellForTopRanking.h"
#import "ContentScrollView.h"
#import "ContentView.h"
#import "rilegouleView.h"
#import "CustomView.h"
#import "ImageContentView.h"


#define WIGHT  [UIScreen mainScreen].bounds.size.width
#define HEIGHT  [UIScreen mainScreen].bounds.size.height

@interface SDP_ViewControllerForCollectionTopRanking ()< UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

// 划线
@property (nonatomic, retain) UIView *viewForTopLine;
@property (nonatomic, retain) UIView *viewForBootomLine;

@property (nonatomic, strong) UIView *viewForSet;
@property (nonatomic, strong) UIImageView *imageViewForUserHeader;  //用户的头像
@property (nonatomic, strong) UIButton *buttonForUserHeader;  //用户的头像点击button
@property (nonatomic, strong) UILabel *labelForUserName;    //用户名
@property (nonatomic, strong) UIButton *buttonForSet;
@property (nonatomic, assign) BOOL isSlected;
@property (nonatomic, retain) UIScrollView *scrollViewForSet;
@property (nonatomic, retain) UIVisualEffectView *visualView;

@property (nonatomic, strong) UITableView *tableView1;

@property (nonatomic, strong) NSMutableArray *arrayForCellData1;

@property (nonatomic, strong) NSString *url;    //用来接收解析数据的url
@property (nonatomic, strong) UIButton *buttonForTemp;  //用来装临时的button

@end

@implementation SDP_ViewControllerForCollectionTopRanking

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    // 判断是否登录过
    if (ISDENGLU) {
        NSLog(@"登录过, 获取用户信息");
        NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userName"]);
        self.labelForUserName.text = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userName"];
        
        [self.imageViewForUserHeader sd_setImageWithURL:[NSURL URLWithString:[[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userImage"]]];
        
        NSLog(@"%@", NSHomeDirectory());
    } else {
        self.labelForUserName.text = @"点击登录后可评论";
        self.imageViewForUserHeader.image = [UIImage imageNamed:@"headimage"];
        
    }

}

#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
 
    self.url = @"http://baobab.wandoujia.com/api/v3/ranklist?_s=6d4918a466442e0421fbd0d3d8695852&f=iphone&net=wifi&strategy=weekly&u=693b683a5db7a43954ed61f0fad8d5f216b94455&v=1.12.0&vc=312";

    [self handleData];
    
    [self creatSetButton];
    
    [self creatTableView];
    
    [self customNavigationBar];
    
}

/** 导航栏添加切换按钮*/
- (void)creatSetButton{

    /** 自定义 button */
    self.buttonForSet = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.buttonForSet setImage:[UIImage imageNamed:@"More"] forState:UIControlStateNormal];
    self.buttonForSet.frame = CGRectMake(20, 20, 30, 40);
    self.buttonForSet.backgroundColor = [UIColor clearColor];
    [self.buttonForSet addTarget:self action:@selector(handelForSet:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:self.buttonForSet];
    self.navigationItem.leftBarButtonItem = menuButton;
    
}

/** 点击设置按钮 */
- (void)handelForSet:(UIBarButtonItem *)button{
    
    
    /** 取反 */
    self.isSlected = !self.isSlected;

    if (self.isSlected) {
        
        if (!self.viewForSet) {
    
            self.viewForSet = [[UIView alloc]init];
            self.viewForSet.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:self.viewForSet];
            self.viewForSet.frame = CGRectMake(0, 64,WIGHT, 0);
            self.viewForSet.alpha = 1;
          
            /** 在 view 上面创建 ScrollView */
            [self creatScrollViewForSet];
            
            /** ScrollView  上的控件*/
            [self creatSetViewForSubViews];

        }
        
        /** 弹窗开关 , 自定义 navigation button*/
        self.buttonForSet = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.buttonForSet setImage:[UIImage imageNamed:@"Morel"] forState:UIControlStateNormal];
        self.buttonForSet.frame = CGRectMake(20, 20, 30, 40);
        self.buttonForSet.backgroundColor = [UIColor clearColor];
        [self.buttonForSet addTarget:self action:@selector(handelForSet:) forControlEvents:UIControlEventTouchUpInside];
       
        UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:self.buttonForSet];
        self.navigationItem.leftBarButtonItem = menuButton;
        

        [UIView animateWithDuration:0.5 animations:^{
            
            self.viewForSet.frame = CGRectMake(0, 64, WIGHT, HEIGHT );
            self.scrollViewForSet.frame = CGRectMake(0, 0, WIGHT,HEIGHT);
            [[NSNotificationCenter defaultCenter] postNotificationName:@"隐藏" object:nil];
        }];
        

    } else {

        self.buttonForSet = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.buttonForSet setImage:[UIImage imageNamed:@"More"] forState:UIControlStateNormal];
        self.buttonForSet.frame = CGRectMake(20, 20, 30, 40);
        self.buttonForSet.backgroundColor = [UIColor clearColor];
        [self.buttonForSet addTarget:self action:@selector(handelForSet:) forControlEvents:UIControlEventTouchUpInside];
       
        
        UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:self.buttonForSet];
        self.navigationItem.leftBarButtonItem = menuButton;
    
        [UIView animateWithDuration:0.5 animations:^{
            
           self.viewForSet.frame = CGRectMake(0, 64, WIGHT, 0);
           self.scrollViewForSet.frame = CGRectMake(0, 0, WIGHT,0);
            [[NSNotificationCenter defaultCenter] postNotificationName:@"显示" object:nil];

        }];
    }
    

    [self.view bringSubviewToFront:self.viewForSet];
    
    // 判断是否登录过
    if (ISDENGLU) {
        NSLog(@"登录过, 获取用户信息");
        
        self.labelForUserName.text = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userName"];
        
        [self.imageViewForUserHeader sd_setImageWithURL:[NSURL URLWithString:[[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userImage"]]];
        
        NSLog(@"%@", NSHomeDirectory());
    } else {
        self.labelForUserName.text = @"点击登录后可评论";
        self.imageViewForUserHeader.image = [UIImage imageNamed:@"headimage"];
        
    }

}


#pragma mark - 创建设置页面
- (void)creatSetViewForSubViews{
    

    // 头像背景图
    UIImageView *viewForLogin = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIGHT, HEIGHT/3)];
    [viewForLogin setImage:[UIImage imageNamed:@"backgroundHeadImage"]];
    viewForLogin.alpha = 1;
    viewForLogin.userInteractionEnabled = YES;
    viewForLogin.backgroundColor = [UIColor orangeColor];
    [self.visualView addSubview:viewForLogin];

    // 头像照片
    self.imageViewForUserHeader = [[UIImageView alloc] initWithFrame:CGRectMake(WIGHT / 2 - WIGHT / 3.5 / 2, HEIGHT / 20, WIGHT / 3.5, WIGHT / 3.5)];
    self.imageViewForUserHeader.userInteractionEnabled = YES;
    self.imageViewForUserHeader.layer.masksToBounds = YES;
    self.imageViewForUserHeader.layer.cornerRadius = WIGHT / 3.5 / 2;
    self.imageViewForUserHeader.layer.borderWidth = 3;
    self.imageViewForUserHeader.layer.borderColor = [UIColor whiteColor].CGColor;
    [viewForLogin addSubview:self.imageViewForUserHeader];
    
    /** 头像 button */
    self.buttonForUserHeader = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonForUserHeader.backgroundColor = [UIColor clearColor];
    self.buttonForUserHeader.frame = self.imageViewForUserHeader.bounds;
    [self.imageViewForUserHeader addSubview:self.buttonForUserHeader];
    [self.buttonForUserHeader addTarget:self action:@selector(buttonForUserHeader:) forControlEvents:UIControlEventTouchUpInside];
    
    // 用户名
    self.labelForUserName = [[UILabel alloc] initWithFrame:CGRectMake(20, HEIGHT / 20 + WIGHT / 3.5 + 5, WIGHT - 40, 23)];
    self.labelForUserName.textAlignment = 1;
    self.labelForUserName.font = [UIFont systemFontOfSize:13];
    [viewForLogin addSubview:self.labelForUserName];
    
    
    /** 收藏 */
    UIButton *buttonForcCollection = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForcCollection.frame = CGRectMake(WIGHT/20, HEIGHT/4, WIGHT/2 - WIGHT/20*2, WIGHT/10);
    [buttonForcCollection setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonForcCollection setTitle:@"  我的收藏" forState:UIControlStateNormal];
    [buttonForcCollection setImage:[UIImage imageNamed:@"iconfont-heart"] forState:UIControlStateNormal];
    buttonForcCollection.titleLabel.font = [UIFont systemFontOfSize:12];
    [viewForLogin addSubview:buttonForcCollection];
    [buttonForcCollection addTarget:self action:@selector(buttonForCollection:) forControlEvents:UIControlEventTouchUpInside];
    
    
    /** 评论 */
    UIButton *buttonForComments = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForComments.frame = CGRectMake(WIGHT/20 + WIGHT/2, HEIGHT/4, WIGHT/2 - WIGHT/20*2, WIGHT/10);
    [buttonForComments setTitle:@"  我的评论" forState:UIControlStateNormal];
    [buttonForComments setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonForComments setImage:[UIImage imageNamed:@"talk"] forState:UIControlStateNormal];
    buttonForComments.titleLabel.font = [UIFont systemFontOfSize:12];
    [viewForLogin addSubview:buttonForComments];
    
    
    /** 我的缓存 */
    UIButton *buttonForCache = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForCache.frame = CGRectMake(WIGHT/2 - WIGHT/3.5/2, HEIGHT/2.6, WIGHT/3.5, WIGHT/15);
    [buttonForCache setTitle:@"我的缓存" forState:UIControlStateNormal];
    buttonForCache.titleLabel.font = [UIFont systemFontOfSize:15];
    [viewForLogin addSubview:buttonForCache];
    
    
    /** 功能开关*/
    UIButton *buttonForFunction = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForFunction.frame = CGRectMake(WIGHT/2 - WIGHT/3.5/2, HEIGHT/2.1, WIGHT/3.5, WIGHT/15);
    [buttonForFunction setTitle:@"功能开关" forState:UIControlStateNormal];
    buttonForFunction.titleLabel.font = [UIFont systemFontOfSize:15];
    [viewForLogin addSubview:buttonForFunction];
    
    


}
- (void)buttonForCollection:(UIButton *)button {
    NSLog(@"dddd");
    self.hidesBottomBarWhenPushed = YES;
    LWH_ViewControllerForCollect *vc = [[LWH_ViewControllerForCollect alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
- (void)buttonForUserHeader:(UIButton *)button {
    NSLog(@"点击了头像");
    if (ISDENGLU) {
        
    } else {
        CWG_ViewControllerForDengLu *cwg_VC = [[CWG_ViewControllerForDengLu alloc] init];
        [self.navigationController pushViewController:cwg_VC animated:YES];
        //self.navigationController.navigationBarHidden = YES;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"隐藏" object:nil];
    }
}


#pragma mark -- 在弹出的  View 上面创建的视图
/** 在弹出的  View 上面添加 tableview */

- (void)creatScrollViewForSet{

    self.scrollViewForSet = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIGHT, 0)];
    self.scrollViewForSet.backgroundColor = [UIColor whiteColor];
    [self.viewForSet addSubview:self.scrollViewForSet];
    self.scrollViewForSet.alpha = 1;
    
    //设置 contentSize 滚动页面范围
    self.scrollViewForSet.contentSize = CGSizeMake(WIGHT, HEIGHT * 1.2) ;
    self.scrollViewForSet.showsVerticalScrollIndicator = YES;
    
    //开启翻页效果.
    self.scrollViewForSet.pagingEnabled = YES;
    
    // 到边缘是否有回弹效果
    self.scrollViewForSet.bounces = NO;
    self.scrollViewForSet.delegate = self;
    
    // 禁止滑动
    self.scrollViewForSet.scrollEnabled = NO;

#pragma mark - scrollView 毛玻璃效果
    
    /** 创建UIBlurEffect类的对象blur, 参数这里使用的是暗黑*/
    UIBlurEffect *blurForHeadImage = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    
    /** 创建UIVisualEffectView的对象visualView, 以blur为参数. */
    self.visualView = [[UIVisualEffectView alloc] initWithEffect:blurForHeadImage];
    
    /** 将visualView的大小等于头视图的大小. (visualView的大小可以自行设定, 它的大小决定了显示毛玻璃效果区域的大小.) */
    self.visualView.frame = CGRectMake(0, 0, WIGHT,HEIGHT);
    
    // 透明度
     self.visualView.alpha = 0.8;
    /** 将visualView添加到blurImageView上. */
    [self.scrollViewForSet addSubview: self.visualView];

}
#pragma mark - 创建TableView 三个
- (void)creatTableView{
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.tableView1 = [[UITableView alloc] initWithFrame:CGRectMake(0, 64 + kWidth / 12, kWidth, kHeight - 64 - 49 - kWidth / 12) style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableView1];
    
    self.tableView1.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView1.backgroundColor = [UIColor whiteColor];
    
    self.tableView1.dataSource = self;
    self.tableView1.delegate = self;
    
    [self.tableView1 registerClass:[EveryDayTableViewCell class] forCellReuseIdentifier:@"cell1"];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kWidth, 40)];
    label.text = @"- The End -";
    label.textAlignment = 1;
    label.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:15];
    self.tableView1.tableFooterView = label;
 //   self.tableView2.tableFooterView = label;
  //  self.tableView3.tableFooterView = label;
    
}

#pragma mark -- tableView 代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (self.arrayForCellData1.count) {
        self.tableView1.tableFooterView.hidden = NO;
    } else {
        self.tableView1.tableFooterView.hidden = YES;
    }
    
    return self.arrayForCellData1.count;
 
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return HEIGHT / 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    EveryDayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
    
    return cell;
}
//添加每个cell出现时的3D动画
-(void)tableView:(UITableView *)tableView willDisplayCell:(EveryDayTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //        CATransform3D rotation;//3D旋转
    //
    //        rotation = CATransform3DMakeTranslation(0 ,50 ,20);
    ////        rotation = CATransform3DMakeRotation( M_PI_4 , 0.0, 0.7, 0.4);
    //        //逆时针旋转
    //
    //        rotation = CATransform3DScale(rotation, 0.9, .9, 1);
    //
    //        rotation.m34 = 1.0/ -600;
    //
    //        cell.layer.shadowColor = [[UIColor blackColor]CGColor];
    //        cell.layer.shadowOffset = CGSizeMake(10, 10);
    //        cell.alpha = 0;
    //
    //        cell.layer.transform = rotation;
    //
    //        [UIView beginAnimations:@"rotation" context:NULL];
    //        //旋转时间
    //        [UIView setAnimationDuration:0.6];
    //        cell.layer.transform = CATransform3DIdentity;
    //        cell.alpha = 1;
    //        cell.layer.shadowOffset = CGSizeMake(0, 0);
    //        [UIView commitAnimations];
    
    
    [cell cellOffset];
    
    EveryDayModel *model = [self.arrayForCellData1 objectAtIndex:indexPath.row];
    
    [cell setModel:model];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self showImageAtIndexPath:indexPath];
    
}


#pragma mark - 设置详情界面

- (void)showImageAtIndexPath:(NSIndexPath *)indexPath{
    
    _array = self.arrayForCellData1;
    
    _currentIndexPath = indexPath;
    
    EveryDayTableViewCell *cell = [self.tableView1 cellForRowAtIndexPath:indexPath];
    CGRect rect = [cell convertRect:cell.bounds toView:nil];
    CGFloat y = rect.origin.y;
    
    _rilegoule = [[rilegouleView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) imageArray:_array index:indexPath.row];
    _rilegoule.offsetY = y;
    _rilegoule.animationTrans = cell.picture.transform;
    _rilegoule.animationView.picture.image = cell.picture.image;
    
    _rilegoule.scrollView.delegate = self;
    
    [[self.tableView1 superview] addSubview:_rilegoule];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"隐藏" object:nil];
    
    //添加轻扫手势
    UISwipeGestureRecognizer *Swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
    
    _rilegoule.contentView.userInteractionEnabled = YES;
    
    Swipe.direction = UISwipeGestureRecognizerDirectionUp;
    
    [_rilegoule.contentView addGestureRecognizer:Swipe];
    
    //添加点击播放手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    [_rilegoule.scrollView addGestureRecognizer:tap];
    
    [_rilegoule aminmationShow];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if ([scrollView isEqual:_rilegoule.scrollView]) {
        
        for (ImageContentView *subView in scrollView.subviews) {
            
            if ([subView respondsToSelector:@selector(imageOffset)] ) {
                [subView imageOffset];
            }
        }
        
        CGFloat x = _rilegoule.scrollView.contentOffset.x;
        
        CGFloat off = ABS( ((int)x % (int)kWidth) - kWidth/2) /(kWidth/2) + .2;
        
        [UIView animateWithDuration:1.0 animations:^{
            _rilegoule.playView.alpha = off;
            _rilegoule.contentView.titleLabel.alpha = off + 0.0;
            _rilegoule.contentView.littleLabel.alpha = off + 0.0;
            _rilegoule.contentView.lineView.alpha = off + 0.0;
            _rilegoule.contentView.descripLabel.alpha = off + 0.0;
            _rilegoule.contentView.collectionCustom.alpha = off + 0.0;
            _rilegoule.contentView.shareCustom.alpha = off + 0.0;
            _rilegoule.contentView.cacheCustom.alpha = off + 0.0;
            _rilegoule.contentView.replyCustom.alpha = off + 0.0;
            
        }];
        
    } else {
        
        NSArray<EveryDayTableViewCell *> *array = [self.tableView1 visibleCells];
        
        [array enumerateObjectsUsingBlock:^(EveryDayTableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            [obj cellOffset];
        }];
        
    }
    
    
}

// 滑动将要结束(左右)
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    if ([scrollView isEqual:_rilegoule.scrollView]) {
        
        int index = floor((_rilegoule.scrollView.contentOffset.x - scrollView.frame.size.width / 2) / scrollView.frame.size.width) + 1;
        
        _rilegoule.scrollView.currentIndex = index;
        
        self.currentIndexPath = [NSIndexPath indexPathForRow:index inSection:self.currentIndexPath.section];
        
        [self.tableView1 scrollToRowAtIndexPath:self.currentIndexPath atScrollPosition:(UITableViewScrollPositionMiddle) animated:NO];
        
        [self.tableView1 setNeedsDisplay];
        EveryDayTableViewCell *cell = [self.tableView1 cellForRowAtIndexPath:self.currentIndexPath];
        
        [cell cellOffset];
        
        CGRect rect = [cell convertRect:cell.bounds toView:nil];
        _rilegoule.animationTrans = cell.picture.transform;
        _rilegoule.offsetY = rect.origin.y;
        
        EveryDayModel *model = _array[index];
        
        [_rilegoule.contentView setData:model];
        
        [_rilegoule.animationView.picture sd_setImageWithURL:[NSURL URLWithString:[model.cover objectForKey:@"feed"]] placeholderImage:nil];
        
    }
    
    
}

#pragma mark - 平移手势触发事件
- (void)panAction:(UISwipeGestureRecognizer *)swipe{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"显示" object:nil];
    [_rilegoule animationDismissUsingCompeteBlock:^{
        
        _rilegoule = nil;
        
    }];
    
}

#pragma mark - 点击手势
- (void)tapAction{

    SDP_PlayerViewController *vc = [[SDP_PlayerViewController alloc] init];
    vc.indexForMovie = self.currentIndexPath.row;
    vc.modelArray = self.array;
    [self presentViewController:vc animated:YES completion:nil];

}






#pragma mark - 自定义导航栏
- (void)customNavigationBar{
    
    // 创建底层的导航栏View
    UIView *viewForNavigationBar = [[UIView alloc] init];
    viewForNavigationBar.frame = CGRectMake(0, 64, WIGHT, WIGHT / 12);
    viewForNavigationBar.backgroundColor = [UIColor whiteColor];
    
    // 周排行 button
    UIButton *buttonForWeekofranking = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForWeekofranking.frame = CGRectMake(WIGHT/40, WIGHT/80, WIGHT/3 - WIGHT/40*2, WIGHT/15);
    [buttonForWeekofranking setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    buttonForWeekofranking.titleLabel.font = [UIFont systemFontOfSize:12];
    [viewForNavigationBar addSubview:buttonForWeekofranking];
    [buttonForWeekofranking setTitle:@"周排行" forState:UIControlStateNormal];
    [buttonForWeekofranking addTarget:self action:@selector(MoveToWeek:) forControlEvents:UIControlEventTouchUpInside];
    
    self.buttonForTemp = buttonForWeekofranking;
    
    // 月排行 button
    UIButton *buttonForMonthRanking = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForMonthRanking.frame = CGRectMake(WIGHT/40 + WIGHT/3, WIGHT/80, WIGHT/3 - WIGHT/40*2, WIGHT/15);
    [buttonForMonthRanking setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    buttonForMonthRanking.titleLabel.font = [UIFont systemFontOfSize:12];
    [viewForNavigationBar addSubview:buttonForMonthRanking];
    [buttonForMonthRanking setTitle:@"月排行" forState:UIControlStateNormal];
    [buttonForMonthRanking addTarget:self action:@selector(MoveToMonth:) forControlEvents:UIControlEventTouchUpInside];
    
    // 总排行 button
    UIButton *buttonForTotalSeniority = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForTotalSeniority.frame = CGRectMake(WIGHT/40 + WIGHT/3*2, WIGHT/80, WIGHT/3 - WIGHT/40*2, WIGHT/15);
    [buttonForTotalSeniority setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    buttonForTotalSeniority.titleLabel.font = [UIFont systemFontOfSize:12];
    [viewForNavigationBar addSubview:buttonForTotalSeniority];
    [buttonForTotalSeniority setTitle:@"总排行" forState:UIControlStateNormal];
    [buttonForTotalSeniority addTarget:self action:@selector(MoveToTotalSeniority:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:viewForNavigationBar];
    [self.view bringSubviewToFront:viewForNavigationBar];
    

    /** 滑动的两条线*/
    
    self.viewForTopLine = [[UIView alloc] init];
    self.viewForTopLine.backgroundColor = [UIColor darkGrayColor];
    self.viewForTopLine.frame = CGRectMake(WIGHT/10,  WIGHT/55, WIGHT/3 - WIGHT/10 *2, WIGHT/600);
    [viewForNavigationBar addSubview:self.viewForTopLine];
    

    self.viewForBootomLine = [[UIView alloc] init];
    self.viewForBootomLine.backgroundColor = [UIColor darkGrayColor];
    self.viewForBootomLine.frame = CGRectMake(WIGHT/10,  WIGHT/90 + WIGHT/17, WIGHT/3 - WIGHT/10 *2, WIGHT/800);
    
    [viewForNavigationBar addSubview:self.viewForBootomLine];

}

// 划线移到周排行
- (void)MoveToWeek:(UIButton *)buttonForWeek {
    
    self.url = @"http://baobab.wandoujia.com/api/v3/ranklist?_s=6d4918a466442e0421fbd0d3d8695852&f=iphone&net=wifi&strategy=weekly&u=693b683a5db7a43954ed61f0fad8d5f216b94455&v=1.12.0&vc=312";
    if (self.buttonForTemp != buttonForWeek) {
        [self handleData];
        self.buttonForTemp = buttonForWeek;
    }
    
    
    
        [UIView animateWithDuration:0.2 animations:^{
            
            self.viewForTopLine.frame = CGRectMake(WIGHT/10  ,WIGHT/55, WIGHT/3 - WIGHT/10 *2, WIGHT/600);
            self.viewForBootomLine.frame = CGRectMake(WIGHT/10,  WIGHT/90 + WIGHT/17, WIGHT/3 - WIGHT/10 *2, WIGHT/800);
        }];
 
}

// 划线移到月排行
- (void)MoveToMonth:(UIButton *)buttonForMonth {

    self.url = @"http://baobab.wandoujia.com/api/v3/ranklist?_s=e01be3da4ade0aafa8fdb96b50fb87e0&f=iphone&net=wifi&strategy=monthly&u=693b683a5db7a43954ed61f0fad8d5f216b94455&v=1.12.0&vc=312";
    if (self.buttonForTemp != buttonForMonth) {
        [self handleData];
        self.buttonForTemp = buttonForMonth;
    }
        [UIView animateWithDuration:0.2 animations:^{
            
            self.viewForTopLine.frame = CGRectMake(WIGHT/2.30769,  WIGHT/55, WIGHT/3 - WIGHT/10 *2, WIGHT/600);
            self.viewForBootomLine.frame = CGRectMake(WIGHT/2.30769,  WIGHT/90 + WIGHT/17, WIGHT/3 - WIGHT/10 *2, WIGHT/800);
        }];

}

// 划线移到总排行
- (void)MoveToTotalSeniority:(UIButton *)buttonForTotalSeniority {
    
    self.url = @"http://baobab.wandoujia.com/api/v3/ranklist?_s=3dfc79715a4a1e6176b4e6b49d74edf0&f=iphone&net=wifi&strategy=historical&u=693b683a5db7a43954ed61f0fad8d5f216b94455&v=1.12.0&vc=312";
    if (self.buttonForTemp != buttonForTotalSeniority) {
        [self handleData];
        self.buttonForTemp = buttonForTotalSeniority;
    }
    
         [UIView animateWithDuration:0.2 animations:^{
          
              self.viewForTopLine.frame = CGRectMake(WIGHT/1.30662,  WIGHT/55, WIGHT/3 - WIGHT/10 *2, WIGHT/600);
              self.viewForBootomLine.frame = CGRectMake(WIGHT/1.30662,  WIGHT/90 + WIGHT/17, WIGHT/3 - WIGHT/10 *2, WIGHT/800);
          }];
}

#pragma mark - 数据解析
- (void)handleData {
    
    // 每日精选接口
    [NetWorkHandler networkingWithUrl:self.url comleteHandle:^(id result, NSData *data) {
        
        self.arrayForCellData1 = [NSMutableArray array];
        
        NSArray *arrayForIssueList = [result objectForKey:@"itemList"];
        
        for (NSDictionary *dic in arrayForIssueList) {
            
            NSDictionary *dicForData = [dic objectForKey:@"data"];
            EveryDayModel *model = [[EveryDayModel alloc] init];
            [model setValuesForKeysWithDictionary:dicForData];
            [self.arrayForCellData1 addObject:model];
            
        }
        [self.tableView1 reloadData];
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
